package com.ems.sys.service.impl;

import com.ems.sys.dao.EmsMoodMapper;
import com.ems.sys.pojo.EmsMood;
import com.ems.sys.service.EmsMoodService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/****
 * @Author:shenkunlin
 * @Description:EmsMood业务层接口实现类
 * @Date 2019/6/14 0:16
 *****/
@Service
public class EmsMoodServiceImpl implements EmsMoodService {

    @Autowired
    private EmsMoodMapper emsMoodMapper;


    /**
     * EmsMood条件+分页查询
     * @param emsMood 查询条件
     * @param page 页码
     * @param size 页大小
     * @return 分页结果
     */
    @Override
    public PageInfo<EmsMood> findPage(EmsMood emsMood, int page, int size){
        //分页
        PageHelper.startPage(page,size);
        //搜索条件构建
        Example example = createExample(emsMood);
        //执行搜索
        return new PageInfo<EmsMood>(emsMoodMapper.selectByExample(example));
    }

    /**
     * EmsMood分页查询
     * @param page
     * @param size
     * @return
     */
    @Override
    public PageInfo<EmsMood> findPage(int page, int size){
        //静态分页
        PageHelper.startPage(page,size);
        //分页查询
        return new PageInfo<EmsMood>(emsMoodMapper.selectAll());
    }

    /**
     * EmsMood条件查询
     * @param emsMood
     * @return
     */
    @Override
    public List<EmsMood> findList(EmsMood emsMood){
        //构建查询条件
        Example example = createExample(emsMood);
        //根据构建的条件查询数据
        return emsMoodMapper.selectByExample(example);
    }


    /**
     * EmsMood构建查询对象
     * @param emsMood
     * @return
     */
    public Example createExample(EmsMood emsMood){
        Example example=new Example(EmsMood.class);
        Example.Criteria criteria = example.createCriteria();
        if(emsMood!=null){
            //
            if(!StringUtils.isEmpty(emsMood.getId())){
                    criteria.andEqualTo("id",emsMood.getId());
            }
            //
            if(!StringUtils.isEmpty(emsMood.getContent())){
                    criteria.andEqualTo("content",emsMood.getContent());
            }
            //
            if(!StringUtils.isEmpty(emsMood.getMoodDate())){
                    criteria.andEqualTo("moodDate",emsMood.getMoodDate());
            }
            //
            if(!StringUtils.isEmpty(emsMood.getRemark())){
                    criteria.andEqualTo("remark",emsMood.getRemark());
            }
        }
        return example;
    }

    /**
     * 删除
     * @param id
     */
    @Override
    public void delete(Integer id){
        emsMoodMapper.deleteByPrimaryKey(id);
    }

    /**
     * 修改EmsMood
     * @param emsMood
     */
    @Override
    public void update(EmsMood emsMood){
        emsMoodMapper.updateByPrimaryKey(emsMood);
    }

    /**
     * 增加EmsMood
     * @param emsMood
     */
    @Override
    public void add(EmsMood emsMood){
        emsMoodMapper.insert(emsMood);
    }

    /**
     * 根据ID查询EmsMood
     * @param id
     * @return
     */
    @Override
    public EmsMood findById(Integer id){
        return  emsMoodMapper.selectByPrimaryKey(id);
    }

    /**
     * 查询EmsMood全部数据
     * @return
     */
    @Override
    public List<EmsMood> findAll() {
        return emsMoodMapper.selectAll();
    }
}
